package org.hadoop;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.*;
import org.junit.Test;

public class Demo02ListFiles {
    @Test
    public void testLitFiles() throws Exception {
        System.setProperty("HADOOP_USER_NAME", "hadoop");
        System.setProperty("HADOOP_HOME", "D:/program/hadoop-3.2.2");
        System.setProperty("hadoop.home.dir", "D:/program/hadoop-3.2.2");
        Configuration config = new Configuration();
        config.set("fs.defaultFS", "hdfs://192.168.56.201:8020");
        FileSystem fs = FileSystem.get(config);
        RemoteIterator<LocatedFileStatus> files =
                fs.listFiles(new Path("/"), true);
        while(files.hasNext()){
            LocatedFileStatus file = files.next();
            System.out.println(file.getPermission()+" "+file.getPath());
        }
        fs.close();
    }
}
